<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./layuimini-v2/pay/css/bootstrap.min.css">
    <link rel="stylesheet" href="./layuimini-v2/pay/css/pay.css">
    <script type="text/javascript" src="./layuimini-v2/pay/js/jquery.min-1.11.1.js"></script>
    <script type="text/javascript" src="./layuimini-v2/pay/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        var payType='ALIPAY';
        var paySubmitting=false;
        var checkPaidTimer = null;
        
        function alipayPaySuccess() {
            //支付成功了，检查一下后台是否被通知到了
            checkPaidTimer=window.setInterval('Pay.runCheckPaid()',3000);
        }
        
        function choosePayType(ths,_payType) {
            payType = _payType;
            $(".payment_table a").removeClass("current");
            $(ths).addClass("current");
        }
        
        function hidePop(id){
            $("#"+id).hide();
        }
        
        function showPop(id){
            $("#"+id).show();
        }
        
        
        var Pay={
            orderId:100,
            submit:function(payType){
                if(paySubmitting){//防止重复提交
                    return;
                }
                paySubmitting=true;
                $("[name='payType']").val(payType);
                
                if(payType=='ALIPAY') {
                    //跳转模式
                    // showPop('popPayConfirm');
                    // $('#formPaySubmit').attr('target', '_blank');
                    // $('#formPaySubmit').submit();
                    // paySubmitting=false;
                    var params = {bizId:100,payType:payType};
                    
                    Pay.submitWeixinScan(params);
                    paySubmitting=false;	
                    
                } else if(payType=='WECHAT') {
                    var params = {bizId:100,payType:payType};
                    
                    Pay.submitWeixinScan(params);
                    paySubmitting=false;	
                }
            },
            finishPay:function(){
                window.location.href="inOrderlist.html";
            },
            
            /*
             *隐藏微信支付
            */
            hideWeixinPay:function(){
                hidePop('divPopMasks');
                hidePop('popWeiXinPay');
            },
            /**
             * 弹出微信支付
             */
            popWeixinPay : function() {
                hidePop('popWeiXinFailure');
                showPop('popWeiXinPay');
                showPop('divPopMasks');
            },
            popZhiFuBaoPay : function() {
                hidePop('popWeiXinFailure');
                showPop('popWeiXinPay');
                showPop('divPopMasks');
            },
            
            /*
             *打开异常
            */
            popQRCodeFailure:function(){
                hidePop('popWeiXinPay');
                showPop('popWeiXinFailure');
            },
            /*
             *显示微信支付二维码
            */
            submitWeixinScan:function (params) {
                $.ajax({
                    type : "POST",
                    url : 'checkOrderQRCode.json',
                    data : params,
                    cache : false,
                    async : false,
                    dataType : "json",
                    success : function(result) {
                        if (result.success) {//
                            var data=result.data;
                            // show qrcode image
                            $('#popWeiXinPayIframe').attr('src','wechatQRCodePay.html?bizId=100');
                            //显示支付二维码
                            Pay.popWeixinPay();
                        }else{
                            if(result.data=='ORDER_ALRADY_PAID'){
                                alert("订单已经支付！",function(){
                                    window.location.href="inOrderlist.html";
                                });
                            }else{
                                Pay.popQRCodeFailure();
                            }
                        }
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        Pay.popQRCodeFailure();
                    }
                });
            },
            submitZhiFuBaoScan:function (params) {
                $.ajax({
                    type : "POST",
                    url : 'checkOrderQRCode.json',
                    data : params,
                    cache : false,
                    async : false,
                    dataType : "json",
                    success : function(result) {
                        if (result.success) {//
                            var data=result.data;
                            // show qrcode image
                            $('#popWeiXinPayIframe').attr('src','wechatQRCodePay.html?bizId=100');
                            //显示支付二维码
                            Pay.popWeixinPay();
                        }else{
                            if(result.data=='ORDER_ALRADY_PAID'){
                                alert("订单已经支付！",function(){
                                    window.location.href="inOrderlist.html";
                                });
                            }else{
                                Pay.popQRCodeFailure();
                            }
                        }
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        Pay.popQRCodeFailure();
                    }
                });
            },
            startRunCheckPaid : function(orderId){
                clearInterval(checkPaidTimer);
                if(orderId){
                    Pay.orderId=orderId;
                }
                
                checkPaidTimer=window.setInterval('Pay.runCheckPaid()',3000);
            },
            /**
             * 运行到款检查
             */
            runCheckPaid:function(){
                try {
                    $.ajax({
                        type : "get",
                        url : 'checkPaid.json',
                        data : {'bizId' : Pay.orderId},
                        cache : false,
                        async : false,
                        dataType : "json",
                        success : function(result) {
                            if (result && result.pay_result && result.pay_result=='paid') {// 已到款
                                //让定时器失效
                                clearInterval(checkPaidTimer);
                                checkPaidTimer=null;
                                alert("支付成功",function(){
                                    window.location.href="inOrderlist.html";
                                });
                            }
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                        }
                    });
                } catch (err) { /* alert(err); */
                }
            }
        }
        
        $(function(){
            $(".operation").mouseover(function(){
                $(".hide1").show();
            }).mouseout(function(){
                $(".hide1").hide();
            });
            
            //支付按钮
            $("#btnCommonSubmit").click(function(){
                Pay.submit(payType);
            });
        });
        </script>
</head>

<body>
    <div class="panel panel-default">
        <!-- 收银台LOGO -->
        <div class="panel-body pay_cashier">
            <div class="col-xs-12">
                <img src="./layuimini-v2/pay/images/cashier.jpg" />
            </div>
        </div>
        <!-- /END CASHIER LOGO -->
        <!-- 支付金额 -->
        <div class="panel-body pay_title" id="moneydisplay">
            <!-- <span class="col-xs-1 control-label text-left">支付金额：</span>
            <div class="col-xs-3" style="color:#ff2832;font-size:18px;">&yen;
                200
            </div>
            <span class="col-xs-1 control-label">申请单号：</span>
            <div class="col-xs-3 text-left">
                SQ201810100001
            </div> -->
        </div>
        <!--/ END 支付金额 -->

        <!-- PAY WAY -->
        <div class="panel-body pay_box">
            <table class="payment_table">
                <tbody>
                    <tr>
                        <!-- <td>
                            <a href="javascript:;" onclick="choosePayType(this,'ALIPAY')" class="selPayType1 current">
                                <img src="./layuimini-v2/pay/images/zhifubao.gif" title="支付宝" width="140" height="40">
                                <span></span>
                            </a>
                        </td> -->
                        <td>
                            <a href="javascript:;" onclick="choosePayType(this,'WECHAT')" class="selPayType1">
                                <img src="./layuimini-v2/pay/images/weixin.gif" title="微信支付" width="140" height="40">
                                <span></span>
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div>
                <a id="btnCommonSubmit" href="javascript:void(0);" class="btn btn_big">立即支付</a>
			</div>
        </div>

        <!-- END PAY WAY -->

        <!--遮罩层-->
        <div id="divPopMasks" class="masks" style="display:none;">
            <iframe style="border:none;height:100%;width:100%;opacity:0;filter:alpha(opacity=0);"></iframe>
        </div>

        <!-- 提交后台发起支付-->
        <form id="formPaySubmit" action="paySubmit.html" method="post" target="_blank">
            <input type="hidden" name="payType" value="" />
            <input type="hidden" name="bizId" value="100" />
        </form>
        <!-- /end提交后台发起支付-->

        <!--微信扫码弹层-->
        <!-- <div id="popWeiXinPay" class="pop_tip" style="display:none;">
            <div class="head_title">
                <div class="title_name">微信扫码支付</div>
                <div class="close" onclick="javascript:Pay.hideWeixinPay();"></div>
            </div>
            <p class="price">支付<span class="amountStr">&yen;
                    <s:property value="orderInfoBO.orderInfo.confirmMoney" /></span>元</p>
            <div class="code2">
                <iframe id="popWeiXinPayIframe" name="weiXinPayIframe" style="width: 170px; height: 170px;" frameborder="no"
                border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes" src="/page/pop-loading.html"></iframe>
                <span class="codew_icon"><img src="./layuimini-v2/pay/images/wei_code2_i.png" /></span>
            </div>
            <a href="javascript:Pay.finishPay();" class="btn_b">若微信支付已完成，请点击！</a>
        </div> -->
        <div id="popWeiXinFailure" class="pop_tip" style="display: none;">
            <!-- <div class="head_title">
                <div class="title_name">微信扫码支付</div>
                <div class="close" onclick="javascript:hidePop('popWeiXinFailure');"></div>
            </div>
            <p class="price">支付
                <span class="amountStr">&yen;
                    <s:property value="orderInfoBO.orderInfo.confirmMoney" />
                </span>100元</p>
            <div class="code2">
                输入支付金额即算支付成功:<br>
            <input style="width: 100px;" id="paymoney">
            </div>
            <a href="javascript:okPay();" class="btn_b">若微信支付已完成，请点击！</a> -->
        </div>
        <!--/END微信扫码弹层-->

        <!-- 推荐支付宝支付开始 -->
        <div class="panel-body pay_recommend">
            <p style="padding-left:15px;">推荐扫码真实支付:</p>
            <div class="scan_code">
                <iframe name="alipayScanIframe"  width="103" height="103" frameborder="0"
                scrolling="no" style="height: 103px;width:103px; border:1px solid #aaa;"></iframe>
                <img style="position:relative;top:-58px;" class="scan" src="./layuimini-v2/pay/images/scan.png" alt=""
                    width="27" height="27">
                <div class="scan_text" style="position:relative;top:-58px;">
                    <span>打开手机支付宝</span><span>扫一扫继续付款</span>
                    <span class="operation" style="background: url(images/right.png) right center no-repeat;">操作演示</span>
                </div>
                <div class="hide1" style="display:none;">
                    <img class="step1" src="./layuimini-v2/pay/images/step1.gif" alt="">
                    <img class="step3" src="./layuimini-v2/pay/images/middle.pn" alt="">
                    <img class="step2" src="./layuimini-v2/pay/images/step2.gif" alt="">
                </div>
            </div>
        </div>
        <!-- 推荐支付宝支付结束 -->



    </div>
    <script>
        var user=JSON.parse(localStorage.getItem('nowuser'))
        if(user==null){
  window.location.href='./index.html'
}
        // alert(user.name+",欢迎您！")
        var strPath = window.document.location.pathname;
        // alert(strPath)
         var data=JSON.parse(localStorage.getItem('paydata'));
         if(data==null){
            alert("支付信息错误，请重新选择购买")
            window.location.href="./HotelUser-hotel.html"
         }
         else{
         localStorage.removeItem('paydata')
                    console.log('data=',data)
        var h='';
        h+="<span class='col-xs-1 control-label text-left'>支付金额：</span>"+
        "<div class='col-xs-3' style='color:#ff2832;font-size:18px;'>&yen;"
            +data.dayPrice+
        "</div>"
        // "<span class='col-xs-1 control-label'>订单号：</span>"+
        // "<div class='col-xs-3 text-left'>"+
        //     "SQ201810100001"+
        // "</div>"
       
        document.getElementById("moneydisplay").innerHTML=h; 
        var j=''
        j+="<div class='head_title'>"+
   "<div class='title_name'>微信扫码支付</div>"+
    "<div class='close' onclick='javascript:hidePop('popWeiXinFailure');'></div>"+
"</div>"+
"<p class='price'>支付"+
    "<span class='amountStr'>&yen;"+
        "<s:property value='orderInfoBO.orderInfo.confirmMoney' />"+
    "</span>"+data.dayPrice+"</p>"+
"<div class='code2'>"+
    "输入支付金额即算支付成功:<br>"+
"<input style='width: 100px;' id='paymoney'>"+
"</div>"+
"<a href='javascript:okPay();' class='btn_b'>若微信支付已完成，请点击！</a>"
document.getElementById('popWeiXinFailure').innerHTML=j
        function okPay(){
           var m=$('#paymoney').val()
           alert(m)
        if(m==data.dayPrice) {
            alert("支付成功")
        //     $.ajax({
        //     type: "Get",
        //     contentType: "application/json", //必须这样写
        //     dataType: "json",
        //     data: paydata,
        //     url: "http://douzi.wiki:9000/GROW/api/room/checkHotelOrder",
        //     success: function (data) {
        //       console.log("aaa");
        //     },
        //   });
            window.location.href="./HotelUser-hotel.html"
            //数据库增加数据
            //跳转到订单页面
        }
        }
    }
        
    </script>
</body>

</html>